import Vue from 'vue'
import VueRouter from 'vue-router'
import login from '@/views/login'

import home from '@/views/home'
import layout from '@/views/layout'
// 路由懒加载 url 与 path 匹配后才加载
// import user from '@/views/user'
const user = () => import('@/views/user')
// import Search from '@/views/search'
const Search = () => import('@/views/search')
// import ArticleDetail from '@/views/ArticleDetail'
const ArticleDetail = () => import('@/views/ArticleDetail')
// import SearchResult from '@/views/search/ressultlist'
const SearchResult = () => import('@/views/search/ressultlist')
// import Edit from '@/views/user/edit'
const Edit = () => import('@/views/user/edit')
// import Xiaoqian from '@/views/XiaoQian'
const Xiaoqian = () => import('@/views/XiaoQian')
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/layout'

  },
  { // 登录
    path: '/login',
    component: login

  },
  {
    // 二级出口
    path: '/layout',
    component: layout,
    redirect: '/layout/home',
    children: [
      {
        // 首页
        path: 'home',
        component: home
      }, {
        path: 'user',
        component: user
      }

    ]

  },
  {
    // 搜索 放大镜
    path: '/search',
    component: Search
  },
  {
    path: '/search/:keywords',
    component: SearchResult
  },
  {
    // 文章详情
    path: '/article',
    component: ArticleDetail
  }, {
    path: '/user/edit',
    component: Edit
  }, {
    path: '/xiaoqian',
    component: Xiaoqian
  }
]

const router = new VueRouter({
  routes
})

export default router
